import logging

import docutils.core

from pylons import request, response, session, tmpl_context as c, url
from pylons.controllers.util import abort, redirect

from cpswarehouse.lib.base import BaseController, render

log = logging.getLogger(__name__)

#%(head_prefix)s
#%(head)s
#%(body_prefix)s

format_doc = """
%(body_pre_docinfo)s
%(docinfo)s
%(body)s
"""
#%(body_suffix)s

from pylons.decorators.cache import beaker_cache

class DocController(BaseController):

    @beaker_cache()
    def rest_doc(self):

        text = open('docs/tutorial.txt').read()
        #text = open(filename).read()
        html_dict = docutils.core.publish_parts(text, writer_name='html')

        c.markup = format_doc % html_dict

        return render('/doc.mako')        

